<template>
	<view v-if="cartList.length !== 0" class="cart-container-box">
		<gy-address></gy-address>
		<view class="cart-title">
			<uni-icons type="shop" size="18"></uni-icons>
			<text class="cart-title-text">购物车</text>
		</view>
		<uni-swipe-action>
			<view v-for="(item,i) in cartList" :key="i">
				<uni-swipe-action-item @click="onClick(item)" :right-options="options">
					<gy-goods @number-change="numberChange" @radio-change="radioChange" :show-num="true"
						:show-radio="true" :goods="item"></gy-goods>
				</uni-swipe-action-item>
			</view>
		</uni-swipe-action>
		<gy-settle></gy-settle>
	</view>
	<view class="empty-cart" v-else>
		<image class="empty-image" src="/static/cart_empty@2x.png"></image>
		<text class="tips">空空如也</text>
	</view>
</template>

<script>
	import {
		mapState,
		mapGetters,
		mapMutations
	} from 'vuex'
	import mixin from '@/mixins/tabbar-badge.js'
	export default {
		mixins: [mixin],
		computed: {
			...mapState('cart', ['cartList']),
		},
		data() {
			return {
				options: [{
					text: '删除',
					style: {
						backgroundColor: '#C00000'
					}
				}]
			}
		},
		methods: {
			onClick(goods) {
				this.deleteGoods(goods)
				this.setBadgeInMixin()
			},
			...mapMutations('cart', ['updateState', 'updateCount', 'deleteGoods']),
			radioChange(e) {
				this.updateState(e)
			},
			numberChange(e) {
				this.updateCount(e)
				this.setBadgeInMixin()
			}
		}
	}
</script>

<style lang="scss">
	.empty-cart{
		padding-top: 100px;
		display: flex;
		flex-direction: column;
		align-items: center;
		.empty-image{
			width: 90px;
			height: 90px;
		}
		.tips{
			font-size: 14px;
			color: gray;
		}
	}
	.cart-container-box {
		padding-bottom: 50px;
	}

	.cart-title {
		padding-left: 5px;
		border-bottom: 1px solid #EFEFEF;
		height: 40px;
		display: flex;
		align-items: center;

		.cart-title-text {
			font-size: 14px;
		}
	}
</style>